package com.ruoyi.common.exception;

import java.util.Arrays;

/**
 * 通用异常类
 * <p>
 * GenericException class
 *
 * @author xxx
 */
public class GenericException extends RuntimeException {

    /**
     *
     */
    private static final long serialVersionUID = 5723709301392096759L;
    /**
     * 状态码
     */
    private String code;
    /**
     * 参数
     */
    private Object[] args;

    /**
     * 默认构造函数（无参）
     */
    public GenericException() {
        super();
    }

    /**
     * 默认构造函数
     *
     * @param code 状态码
     * @param message 状态描述
     */
    public GenericException(String code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 默认构造函数
     *
     * @param code 状态码
     * @param message 状态描述
     * @param cause 异常消息堆栈
     */
    public GenericException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public GenericException setCode(String code) {
        this.code = code;
        return this;
    }

    public GenericException setArgs(Object... args) {
        this.args = args.clone();
        return this;
    }

    public Object[] getArgs() {
        if (args == null) {
            return null;
        }
        return args.clone();
    }

    @Override
    public String toString() {
        return "GenericException{" +
                "code='" + code + '\'' +
                ", args=" + Arrays.toString(args) +
                "} " + super.toString();
    }
}
